from django.http import HttpResponse
import mimetypes
import os

def sendEmail(request):
    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr
    msg = MIMEText(request.GET.get("yzm"), 'plain', 'utf-8')
    msg['From'] = formataddr(['Talking', "mailofngzm@foxmail.com"])
    msg['To'] = formataddr(['尊敬的用户',request.GET.get("email")])
    msg['Subject'] = "您的验证码为"
    server = smtplib.SMTP_SSL("smtp.qq.com", 465)
    server.login("mailofngzm@foxmail.com", "jrxwcxtbsfdseahh")
    server.sendmail("mailofngzm@foxmail.com", [request.GET.get("email")], msg.as_string())
    server.quit()
    return HttpResponse("")
def handelFile(request, path):
    if os.path.exists("files/"+path):
        type, encoding = mimetypes.guess_type(path)
        return HttpResponse(open("files/" + path, "rb"), content_type=type)
    else:
        return HttpResponse(open("files/icon/default.png", "rb"), content_type="image/png")